package com.xiaotao.publisher;

import com.xiaotao.util.RabbitMqUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class UserCouponPublisher {
    @Resource
    private RabbitMqUtil rabbitMqUtil;
    @Resource
    private RabbitTemplate rabbitTemplate;
    public void send(Integer msg,Integer timeout){
        rabbitTemplate.setReturnsCallback(rabbitMqUtil);
        rabbitTemplate.setConfirmCallback(rabbitMqUtil);
        rabbitTemplate.convertAndSend("userCoupon","checkCoupon",msg,message -> {
            message.getMessageProperties().setDelay(timeout);
            return message;
        });
    }
}
